var app = getApp();
Component({
    properties: {
        itemout : Object,
        params : Object,
        lat : Number,
        lng : Number,
        shopid : Number,
    },
    data: {
        datalist : [],
        page : {
            isend : false,
            doing : false,
            doo : 'index_v1',
            pdata : {
                op : 'list',
                page : 1,
                otype : 0,
                stype : 0,
                gtype : 0,
                sortid : 0,
                shopid : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
    },
    options : {
        addGlobalClass : true,
    },
    ready:function(){
        var self = this;

        self.data.downget = true;
        self.data.page.isend = false;
        self.data.page.doing = false;
        self.data.page.pdata.page = 1;
        if( self.data.itemout && self.data.itemout.params ){
            self.setData({
                datalist : [],
                'page.pdata.stype' : self.data.itemout.params.style
            });

            self.data.page.pdata.otype = self.data.itemout.params.ordertype;
            for (var t in self.data.itemout.params) {
                if(t != 'data' && t != 'sortlist') {
                    self.data.page.pdata[`${t}`] = self.data.itemout.params[t];
                }
            }
            
        }
        this.load();
    },
    methods: {
        setparams(){

        },
        setlat(lat,lng){
            this.data.page.pdata.lat = lat;
            this.data.page.pdata.lng = lng;
        },
        setlist(e){
            this.data.downget = true;
            this.data.page.isend = false;
            this.data.page.doing = false;
            this.data.page.pdata.page = 2;
            this.data.page.pdata.sortid = e.detail.sortid;
            this.data.page.pdata.sorttwo = e.detail.sorttwo;
            this.setData({
                datalist : e.detail.list,
            })
        },
        reset(){
            this.setData({
                datalist : [],
                'page.pdata.page' : 1,
                'page.isend' : false,
            });
            this.load('down');
        },
        load : function(){
            var self = this;
            self.data.page.pdata.shopid = self.data.shopid ? self.data.shopid : 0;
            self.data.page.pdata.lat = self.data.lat ? self.data.lat : 0;
            self.data.page.pdata.lng = self.data.lng ? self.data.lng : 0;
            
            app.com.getPage(self,self.data.page,20,false,function(res){
                self.setData({
                    datalist : self.data.datalist.concat(res.data.data.list)
                });
            });
        },
        navigateto : function( e ){
            var self = this;
            if( self.data.params.indexmes == 1 || !wx.requestSubscribeMessage ){
                app.com.navigateto( e );
            }else{
                wx.requestSubscribeMessage({
                    tmplIds : self.data.params.submess,
                    complete : function(){
                        app.com.navigateto( e );
                    }
                })
            }
        },
    }
});